﻿//-----------------------------------------------------------------------
// <author>Paul Long</author>
//-----------------------------------------------------------------------

namespace TopUserExceptions
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Runtime.Serialization;
    using System.Security.Permissions;
    using System.Text;

    /// <summary>
    /// Provides exception handling for NMAPI.
    /// </summary>
    [Serializable]
    public class ParsingException : System.Exception, ISerializable
    {
        /// <summary>
        /// Maintains the error message passed into the exception constructor.
        /// </summary>
        private string errorMessage;

        /// <summary>
        /// Initializes a new instance of the ParsingException class.
        /// </summary>
        public ParsingException()
        {
        }

        /// <summary>
        /// Initializes a new instance of the ParsingException class.
        /// Constructor with one string argument.
        /// </summary>
        /// <param name="errorMessage">Error Message of exception.</param>
        public ParsingException(string errorMessage)
        {
            this.errorMessage = errorMessage + "\n" + base.Message;
        }

        /// <summary>
        /// Initializes a new instance of the ParsingException class.
        /// Constructor with error message and previous exception.
        /// </summary>
        /// <param name="errorMessage">Error Message of exception.</param>
        /// <param name="exception">Previous Exception</param>
        public ParsingException(string errorMessage, Exception exception)
        {
            this.errorMessage = errorMessage + "\n" + exception.Message;            
        }

        /// <summary>
        /// Initializes a new instance of the ParsingException class.
        /// Constructor with serialization.
        /// </summary>
        /// <param name="serializationInfo">Serialization Info</param>
        /// <param name="streamingContext">Streaming Context</param>
        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        protected ParsingException(SerializationInfo serializationInfo, StreamingContext streamingContext) : base(serializationInfo, streamingContext)
        {            
        }
        
        /// <summary>
        /// Returns the error message from the exception.
        /// </summary>
        public override string Message
        {
            get
            {
                return this.errorMessage;
            }
        }

        /// <summary>
        /// Override for GetObjectData.
        /// Constructor with serialization.
        /// </summary>
        /// <param name="info">Serialization Info</param>
        /// <param name="context">Streaming Context</param>
        [SecurityPermissionAttribute(SecurityAction.Demand, SerializationFormatter = true)]
        public override void GetObjectData(SerializationInfo info, StreamingContext context)
        {
            base.GetObjectData(info, context);
        }
    }
}
